using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
using DG.Tweening;

public class Ranking : MonoBehaviour
{
    [SerializeField]
    private InputField _nameInput;

    [SerializeField]
    private CanvasGroup _blackScreen;

    [SerializeField]
    private Text _scoreText;

    private float _myTime;


    private void Start()
    {
        Level.Win += Level_Win;

        _blackScreen.alpha = 0f;
    }

    private void Level_Win(float time)
    {
        Show(time);
    }

    private void Show(float time)
    {
        _blackScreen.blocksRaycasts = true;
        _blackScreen.DOFade(1f, 1f);

        _myTime = time;

        string score;
        if (!PlayerPrefs.HasKey("Best") ||
            PlayerPrefs.GetFloat("Best") > time)
        {
            PlayerPrefs.SetFloat("Best", time);
            PlayerPrefs.Save();
            score = $"你的用时为{time:0.0}, 刷新了记录！";
        }
        else
        {
            float best = PlayerPrefs.GetFloat("Best");
            score = $"你的用时为{time:0.0}, 最低用时记录{best:0.0}";
        }
        _scoreText.text = score;
    }
}
